package top.xqf.homework.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import top.xqf.homework.base.BasePageResult;
import top.xqf.homework.dao.TbYsRoleDAO;
import top.xqf.homework.entity.PageBean;
import top.xqf.homework.entity.TbYsRole;
import top.xqf.homework.service.RoleService;

import java.util.List;
import java.util.Optional;

@Service
public class RoleServiceImpl implements RoleService {
    private final TbYsRoleDAO tbYsRoleDAO;

    public RoleServiceImpl(TbYsRoleDAO tbYsRoleDAO) {
        this.tbYsRoleDAO = tbYsRoleDAO;
    }


    @Override
    public BasePageResult<List<TbYsRole>> query(TbYsRole tbYsRole, PageBean page) throws Exception{
        page= Optional.ofNullable(page).orElse(new PageBean());
        PageHelper.startPage(page.getPageNumber(),page.getPageSize());
        List<TbYsRole> list=tbYsRoleDAO.query(tbYsRole);
        page.setPageInfo(new PageInfo<>(list));
        BasePageResult<List<TbYsRole>> result=new BasePageResult<>();
        result.setCode(200);
        result.setSuccess(true);
        result.setMessage("");
        result.setData(list);
        result.setPage(page);
        return result;
    }
}

